package com.tomecode.tools.maven.settings.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Modifications to the build process which is keyed on some sort of
 * environmental parameter.
 * 
 * @author Tomas Frastia
 * @see http://www.tomecode.com or
 *      http://code.google.com/p/maven-settings-editor/
 * 
 */
public final class Profile {

	private String id;
	/**
	 * The lists of the remote repositories.
	 */
	private final List<Repository> repositories;
	/**
	 * The lists of the remote repositories for discovering plugins.
	 */
	private final List<PluginRepository> pluginRepositories;
	/**
	 * The conditional logic which will automatically trigger the inclusion of
	 * this profile.
	 */
	private Activation activation;
	/**
	 * Extended configuration specific to this profile goes here. Contents take
	 * the form of property.value
	 */
	private final Properties properties;

	public Profile() {
		activation = new Activation();
		repositories = new ArrayList<Repository>();
		pluginRepositories = new ArrayList<PluginRepository>();
		properties = new Properties();
	}

	public Profile(String id) {
		this();
		this.id = id;
	}

	/**
	 * Copy exits {@link Profile} to new {@link Profile}
	 * 
	 * @param profile
	 */
	public Profile(Profile profile) {
		this(profile.getId());
		activation = new Activation(profile.getActivation());
		for (Repository repository : profile.getRepositories()) {
			repositories.add(new Repository(repository));
		}
		for (PluginRepository pluginRepository : profile.getPluginRepositories()) {
			pluginRepositories.add(new PluginRepository(pluginRepository));
		}
		properties.putAll(profile.getProperties());
	}

	public final String getId() {
		return id;
	}

	public final void setId(String id) {
		this.id = id;
	}

	public final List<Repository> getRepositories() {
		return repositories;
	}

	public final void addRepository(Repository repository) {
		repositories.add(repository);
	}

	public final void setRepositories(List<Repository> repositories) {
		this.repositories.addAll(repositories);
	}

	public final List<PluginRepository> getPluginRepositories() {
		return pluginRepositories;
	}

	public final void setPluginRepositories(List<PluginRepository> pluginRepositories) {
		this.pluginRepositories.addAll(pluginRepositories);
	}

	public final Activation getActivation() {
		return activation;
	}

	public final void setActivation(Activation activation) {
		this.activation = activation;
	}

	public final Properties getProperties() {
		return properties;
	}

	public final void addProperty(String name, String value) {
		properties.put(name, value);
	}

	public final void setProperty(Properties properties) {
		this.properties.clear();
		this.properties.putAll(properties);
	}

	public final String toString() {
		return id;
	}

	public final void addPluginRepository(PluginRepository pluginRepository) {
		this.pluginRepositories.add(pluginRepository);
	}
}
